<template>
  <div class="TreeSelect">
    <div class="coent" style="font-size:18px"></div>
  </div>
</template>
<script>
import { ExecProcedure, CreateProcess, PlatSendTask, PrepareCreateProcess, FileServerProxy } from '../../utils/api'
export default {
  data() {
    return {
      items: [],
      ifID: '',
      TASK_ID: '',
      activeIds: [],
      activeIndex: 0,
      tableData: [],
      indexData: [],
      tableData1: [],
      code1: '',
      xcfy: '',
      rowGuid: ''
    }
  },
  mounted() {
    if (ZWJSBridge) {
      ZWJSBridge.setTitle({
        title: '选择人员'
      })
        .then(res => {
        })
        .catch(err => {
        })
    }
  },
  methods: {
    getData: async function (data) {
      //获取人员
      let params = {
        accessCode: '0a709d649c314903a72225edb8bc8c2a',
        cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
        params: {
          taskId: data.TASK_ID,
          direction: 0,
          token: window.localStorage.getItem('token')
        }
      }
      const res = await FileServerProxy(params)
      let data1 = JSON.parse(res.data.data)
      if (data1.SendData.length > 1) {
        //调用存储过程
        var USERID = ''
        let paramsData = {}
        // 农户危房申请阶段
        if (this.$route.query.data.TASK_ID.NODE_GUID === '{5E869057-F0CA-4E87-80D4-9B7FECEAFE9E}') {
          USERID = data.JDJGID
          paramsData.procName = 'up_processusername'
          paramsData.dtParams = JSON.stringify([{ I_USERID: USERID, TYPE: 4 }])
        } else {
          paramsData.procName = 'SFZHUSER'
          var CW = "'"+data.CERTIFICATECODE+"'"
          var NH = "'"+data.DBRSFZH+"'"
          USERID = CW + ',' + NH
          paramsData.dtParams = JSON.stringify([{ I_USERID: USERID }])
        }
        paramsData.token = window.localStorage.getItem('token')
        let paer = {
          // procName: "USERNAME",
          // dtParams: JSON.stringify([{ I_USERID: USERID }]),
          accessCode: '69db6bece3a7480592e2ec753d1e335e',
          cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
          params: paramsData
          // "params": {
          //   "procName": "USERNAME",
          //   "dtParams": JSON.stringify([{ I_USERID: USERID }]),
          //   "token": window.localStorage.getItem("token"),
          // }
        }

        const req = await FileServerProxy(paer)
        let reqData = JSON.parse(req.data.data)
        data1.SendData.forEach(item => {
          if (item.PTNID == -1) {
            this.tableData.push(item)
          }
        })
        reqData.Data.forEach(j => {
          var nodeItem //获取修改的流程节点对象
          var maxtnid //获取tnid最大值
          for (var i = 0; i < this.tableData.length; i++) {
            let item = this.tableData[i]
            var curTnid = item.TNID
            if (!maxtnid) {
              maxtnid = curTnid
            } else if (curTnid > maxtnid) {
              maxtnid = curTnid
            }
          }
          var tnid = this.tableData[0].TNID
          var newItem = {}
          maxtnid = i + 1
          newItem.TNID = maxtnid
          newItem.PTNID = tnid
          newItem.TEXT = j.USERNAME
          newItem.USERID = j.USERID
          newItem.AUTOCHECKED = ''
          newItem.WFNODEGUID = this.tableData[0].WFNODEGUID
          newItem.WFNODENAME = this.tableData[0].WFNODENAME
          newItem.WFNODETYPE = this.tableData[0].WFNODETYPE
          newItem.SINGLEASSIGN = this.tableData[0].SINGLEASSIGN
          newItem.ISUSER = 1
          this.tableData.push(newItem)
        })
        this.indexData = this.tableData
      }
      this.ifID = data.WF_GUID
      this.rowGuid = data.ROW_GUID
      //获取人员信息并且传入到数组中只要补位-1的子集
      //村上值后调用发送接口
     this.handleGoToNext()
    },
    onClickLeft() {
      this.$router.back(-1)
    },
    handleGoToNext: async function () {
      //判断当前是否选择了人员
      if (this.indexData.length > 0) {
        if (this.$route.query.data.TASK_ID) {
          let plantask = {
            // taskId: resCreateData.TaskId,
            // direction: 0,
            // wfBoxGuid: "",
            // actionText: "",
            // taskName: "",
            // wfGuid: this.xcfy,
            // sendNodes: JSON.stringify(this.indexData),
            accessCode: 'c52bcf7cf3fb42bb9fbcd9b91e97d411',
            cityCode: window.localStorage.getItem('citycode') ? window.localStorage.getItem('citycode') : '441300000000',
            params: {
              taskId: this.$route.query.data.TASK_ID.TASK_ID,
              direction: 0,
              wfBoxGuid: '',
              actionText: '同意',
              taskName: '',
              wfGuid: this.xcfy,
              sendNodes: JSON.stringify(this.indexData),
              token: window.localStorage.getItem('token')
            }
          }
          const respl = await FileServerProxy(plantask)
          // const respl = await PlatSendTask(plantask);
          let data = JSON.parse(respl.data.data).Success
          // JSON.parse(resCreate.data.data)
          if (data) {
            this.$toast.success('成功！')
            // this.$notify({ type: "success", message: "成功！" });
            setTimeout(() => {
              this.$router.push({
                path: '/FeatureList'
              })
            }, 500)
          }
        }
      } else {
        this.$toast.fail('请选择人员！')
        // this.$notify({ type: "danger", message: "请选择人员！" });
      }
    }
  },
  mounted() {
    //接收浙里办传来的参数
    if (this.$route.query.data.TASK_ID.NODE_GUID == '{F81FCB82-7196-4E94-BFF5-159E1CEBEFF8}') {
      //基槽验线
      this.xcfy = '{460B4B5F-C3C2-4D4D-A702-17D4B4A3252F}'
    } else if (
      this.$route.query.data.TASK_ID.NODE_GUID == '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}' ||
      this.$route.query.data.TASK_ID.NODE_GUID == '{FAFEF7FF-6294-489A-A5DF-53906712EBEE}'
    ) {
      //现场放杨
      this.xcfy = '{612C9C60-8D18-4D23-BF32-E9D9D01BB0EA}'
    } else if (this.$route.query.data.TASK_ID.NODE_GUID == '{10BAEA52-EDDE-48C7-97AD-C211D272010E}') {
      //一层立模
      this.xcfy = '{7F042B34-7091-4884-A5D6-A615AE55497D}'
    } else if (this.$route.query.data.TASK_ID.NODE_GUID == '{C89D1E12-1303-482F-BB9E-45457905C759}') {
      //竣工验收
      this.xcfy = '{8FAD71FB-7756-4F0A-BEE8-4F6397B075A8}'
    } else if (this.$route.query.data.TASK_ID.NODE_GUID == '{5E869057-F0CA-4E87-80D4-9B7FECEAFE9E}') {
      //农户危改申请
      this.xcfy = '{DF6C42D5-2BED-473B-9C4D-DA8C42DAF7E9}'
    }
    this.getData(this.$route.query.data.TASK_ID)
    //调用视图减少人员选择
  }
}
</script>
<style lang="scss" scoped>
.TreeSelect {
  height: 100vh;
  background: #fff;
  font-size: 0.2em;
}
</style>
